package com.dmx.cep.dao.impl;

import java.util.List;

import com.dmx.cep.dao.UserBaseInfoDao;
import com.dmx.cep.entity.UserBaseInfo;
import com.dmx.fw.dao.hibernateimpl.BaseDaoImpl;

public class UserBaseInfoDaoImpl extends BaseDaoImpl implements UserBaseInfoDao {

    public void batchDeleteUserBaseInfoByIds(String[] ids){
    	if(ids==null){
    		throw new IllegalArgumentException("arg ids couldn't be null for UserBaseInfoDaoImpl.batchDeleteUserBaseInfoByIds");
    	}
        if (ids != null) {
            for(String id:ids){
               deleteUserBaseInfoById(id);
            }
        }
    }

    public void deleteUserBaseInfoById(String id){
    	UserBaseInfo userBaseInfo = findUserBaseInfoById(id);
    	if(userBaseInfo!=null)
    		super.getHibernateTemplate().delete(userBaseInfo);
    }

    public void saveOrUpdateUserBaseInfo(UserBaseInfo userBaseInfo){
        super.getHibernateTemplate().saveOrUpdate(userBaseInfo);
    }

    public UserBaseInfo findUserBaseInfoById(String id){
    	if(id==null||"".equals(id)){
    		throw new IllegalArgumentException("arg id couldn't be null for UserBaseInfoDaoImpl.deleteUserBaseInfoById");
    	}
        String hql = "from UserBaseInfo where uid =?";
        List<UserBaseInfo> userBaseInfos = this.getHibernateTemplate().find(hql,id);
        if(!userBaseInfos.isEmpty()) return userBaseInfos.get(0);
        return null;
    }
	
	
}
